﻿Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient

Public Class TUNIT
    Public UNITNAME As String = ""   '单位名称
    Public UNITCODE As String = ""   '单位编码
    Public UNITTYPE As String = ""   '单位类型
    Public UNITADDR As String = ""   '单位地址


    Public DATA201301 As Double = 0  '2013年1月的税额


    Property 单位名称
        Get
            Return UNITNAME
        End Get
        Set(value)
            UNITNAME = value
        End Set
    End Property

    Property 单位编码
        Get
            Return UNITCODE
        End Get
        Set(value)
            UNITNAME = value
        End Set
    End Property

    Property 税额2013年1月
        Get
            Return DATA201301
        End Get
        Set(value)
            DATA201301 = value
        End Set
    End Property


    Public Shared Function GetHashTabl(ByVal aSQLDataReader As SqlDataReader) As Hashtable

        Dim HashTabl As New Hashtable

        Do While aSQLDataReader.Read

            Dim UnitObjt As New TUNIT
            UnitObjt.UNITCODE = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_SCode"))
            UnitObjt.UNITNAME = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_Name"))
            UnitObjt.UNITTYPE = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_TYPE"))

            If Not aSQLDataReader.IsDBNull(aSQLDataReader.GetOrdinal("DW_ZCDZ")) Then
                UnitObjt.UNITADDR = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_ZCDZ"))
            End If

            HashTabl.Add(UnitObjt.UNITCODE, UnitObjt)
        Loop
        
        Return HashTabl

    End Function

    Public Shared Function GetListObjt(ByVal aSQLDataReader As SqlDataReader) As List(Of TUNIT)

        Dim ListObjt As New List(Of TUNIT)

        Do While aSQLDataReader.Read

            Dim UnitObjt As New TUNIT
            UnitObjt.UNITCODE = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_SCode"))
            UnitObjt.UNITNAME = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_Name"))
            UnitObjt.UNITTYPE = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_TYPE"))

            If Not aSQLDataReader.IsDBNull(aSQLDataReader.GetOrdinal("DW_ZCDZ")) Then
                UnitObjt.UNITADDR = aSQLDataReader.GetString(aSQLDataReader.GetOrdinal("DW_ZCDZ"))
            End If

            ListObjt.Add(UnitObjt)
        Loop
        Return ListObjt

    End Function

    Public Shared Function HashToList(ByVal aHashTabl As Hashtable) As List(Of TUNIT)
        Dim ListObjt As New List(Of TUNIT)
        Dim de As DictionaryEntry

        Dim UnitA As TUNIT
        Dim UnitX As TUNIT
        For Each de In aHashTabl
            UnitA = de.Value

            UnitX = New TUNIT()
            UnitX.DATA201301 = UnitA.DATA201301
            UnitX.UNITADDR = UnitA.UNITADDR
            UnitX.UNITCODE = UnitA.UNITCODE
            UnitX.UNITNAME = UnitA.UNITNAME
            UnitX.UNITTYPE = UnitA.UNITTYPE

            ListObjt.Add(UnitX)
        Next

        Return ListObjt
    End Function



End Class
